package bm.com.project.server.common.controller;

import bm.com.framework.common.config.EnumCode;
import bm.com.framework.common.config.EnumRoute;
import bm.com.project.server.common.dto.BmSysChangeOrgListDTO;
import bm.com.project.server.common.dto.VerifyCodeDTO;
import bm.com.project.server.common.service.CommonService;
import bm.com.framework.common.resp.ResultVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(EnumRoute.CommonRoute.Base)
//@Api("公共模块")
public class CommonController {

    @Resource
    CommonService commonService;

    /**
     * 获取图形验证码
     */
    @PostMapping(EnumRoute.CommonRoute.api.GET_IMAGE_VERIFY_CODE)
    public void getImageVerifyCode() {

    }

    /**
     * 获取文字验证码
     * @param verifyCodeDTO
     * @return
     */
    @PostMapping(EnumRoute.CommonRoute.api.GET_WORD_VERIFY_CODE)
    public ResultVO getWordVerifyCode(@RequestBody VerifyCodeDTO verifyCodeDTO){
//        ValidatorUtils.validateEntity(verifyCodeDTO);
        String verifyCode = commonService.getVerifyCode(verifyCodeDTO);

        HashMap<String, String> code = new HashMap<>();
        code.put("verifyCode",verifyCode);
        return ResultVO.success(EnumCode.CODE_SUCCESS,"获取成功",code);
    }

    /**
     * 通过手机号获取组织列表
     * @param mobile
     * @return
     */
    @PostMapping(EnumRoute.CommonRoute.api.GET_ORG_LIST_BY_MOBILE)
    public ResultVO getOrgListByMobile(@RequestBody(required = false) Map<String,String> mobile){
        List<BmSysChangeOrgListDTO> orgListByMobile = commonService.getOrgListByMobile(mobile.get("mobile"));
        return ResultVO.success(EnumCode.CODE_SUCCESS,"获取成功",orgListByMobile);
    }


}
